﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Runda.EShop.Common.Entity;
using Runda.EShop.Bll;
using Runda.EShop.Common.Utility;
using System.Data;

namespace Runda.EShop.SaaS.CustomerManage
{
    public partial class CustomerList : BasePage
    {
        public Guid EntID
        {
            get {
                return new Guid(Request.QueryString["EntID"]);
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //BizEnterpriseEntity entity = new BizEnterpriseBll().Get<BizEnterpriseEntity>(EntID);
                //ltlEntCode.Text = entity.EntCode;
                //ltlEntName.Text = entity.EntName;

                BindGrid(ConstHelper.PAGE_INIT_INDEX);
            }
        }

        private void BindGrid(int PageIndex)
        {
            List<SqlDbParameter> parms = new List<SqlDbParameter>();
            SqlDbParameter parm = null;
         
            parm = new SqlDbParameter();
            parm.ColumnName = "[EntID]";
            parm.ColumnType = DbType.Guid;
            parm.ParameterName = "@EntID";
            parm.ParameterValue = EntID;
            parm.QualificationType = SqlDbParameter.QualificationSymbol.Equal;
            parms.Add(parm);
            
            int RecordCount = 0;
            List<BizCustomerEntity> list = new BizCustomerBll().GetAll<BizCustomerEntity>(parms, "CustomerCode DESC", AspNetPager1.PageSize, PageIndex, out RecordCount);

            gvCustomerList.DataSource = list;
            gvCustomerList.DataBind();

            AspNetPager1.RecordCount = RecordCount;
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            BindGrid(AspNetPager1.CurrentPageIndex - 1);
        }

        protected void btnRefersh_Click(object sender, EventArgs e)
        {
            BindGrid(AspNetPager1.CurrentPageIndex - 1);
        }
                 
    }
}